/**
 * @param {number[]} nums
 * @return {number}
 */
// 超时
 var maxSumMinProduct = function(nums) {
    const n = nums.length, mod = Math.pow(10,9) + 7
    const sum = new Array(n).fill(0)
    sum[0] = nums[0]
    for(let i = 1; i<n; i++)
        sum[i] = sum[i-1] + nums[i]
    let ans = Number.MIN_SAFE_INTEGER
    for(let i = 1; i<n; i++){
        for(let j = 0; j<i; j++){
            let list = nums.slice(j,i+1)
            let x = sum[i] - sum[j] + nums[j]
            let temp = Math.min(...list) * x % mod
            ans = Math.max(ans, temp)
        }
    }
    for(let x of nums)
        ans = Math.max(ans, x**2 % mod)
    return ans
};